Question 1

Question II

Write some R code to plot the Weibull distribution for the parameters b = 5 and η = 1.

  1. R code [1 mark]
  2. Paste the plot here [1 mark]
  1. Use the newton’s method in the course handout and write suitable functions for f, df and df2. Then generate 1,000 variates from a Weibull with b = 5 and η = 1 and check how well newton’s method is able to recover the estimates of the parameters.

You will follow the following steps to get this done:

  1. code for generating the 1,000 variates from a Weibull with b = 5 and η = 1. Use set.seed(1123) to ensure everyone has the same data. [1 mark]
    set.seed(1123)
    shape <- 5
    scale <- 1
    n <- 1000
    x <- rweibull(n, shape, scale)
  1. Find the score vector (column of first derivatives). [4 marks]
$$ \frac{\delta \mathcal{L}}{\delta \eta} = -\frac{n b}{\eta} +\frac{\eta}{b}\sum_{i=1}^{n} \frac{X_{i}}{\eta}^{b} $$$$ \frac{\delta\mathcal{L}}{\delta b} = \frac{n}{b} - n\ln{\eta} + \sum_{i=1}^{n}\ln{X_{i}} - \sum_{i=1}^{n}\frac{X_{i}}{\eta}^{b}\ln{\frac{X_{i}}{\eta}} $$
  1. Write an R function for the first derivatives (df) which you will use in the Newton Raphson method. [ 4 marks]
  1. Find the hessian matrix (matrix of second derivatives which we call df2). [ 4 marks] $$ \frac{\delta^{2}\mathcal{L}}{\delta \eta^{2}} = \frac{b}{\eta^2}\left[n-(b - 1)\sum_{i=1}^{n}\frac{X_{i}}{\eta}^{b}\right]\\ \frac{\delta^{2}\mathcal{L}}{\delta b^{2}} = \frac{n}{b^{2}} - \sum_{i=1}^{n} \frac{X_{i}}{\eta}^{b}\left[\ln{\frac{X_{i}}{\eta}}\right]^2\\ \frac{\delta^{2}\mathcal{L}}{\delta b \delta\eta} = \frac{\delta^{2}\mathcal{L}}{\delta\eta\delta b} = -\frac{1}{\eta}\left[n - \sum_{i=1}^{n}\left(\frac{x_{i}}{\eta}\right)^{b}-b\sum_{i=1}^{n}\left(\frac{X_{i}}{\eta}\right)^{b}\ln{\frac{X_{i}}{\eta}}\right] $$
  2. Write an R function for the hessian matrix (df2) which you will use in the newton Raphson method. [ 4 marks]
  1. Apply the Newton Raphson Method in R and give the output. Comment on your results. [ 4 marks]